package shopping;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import javax.swing.*;

/**
一些测试语句，与系统无关,可忽略
***/
public class JFrameBackground extends JFrame{

	//JFrame jf = new JFrame();
	JPanel GImage = null;
	Container c = getContentPane();

	public JFrameBackground() {
		initFrame();
	}

	// 初始化窗口
	public void initFrame() {
		// 利用JPanel添加背景图片

		GImage = new JPanel() {

			protected void paintComponent(Graphics g) {
				URL url = JFrameBackground.class.getResource("1psu.jpg");
				ImageIcon icon = new ImageIcon(url);
				Image img = icon.getImage();
				g.drawImage(img, 0, 0, icon.getIconWidth(), icon.getIconHeight(), icon.getImageObserver());
				setSize(icon.getIconWidth(), icon.getIconHeight());

			}

		};
		setTitle("一个不知道起啥名的商城");
		//jf.add(GImage);
		setLayout(null);
		setBounds(50, 50, 200, 150); 
		JButton jbu = new JButton("anniu");

		jbu.setBounds(10, 30, 80, 30);;
		
		//jbu.setMaximumSize(new Dimension(9, 30)); // 设置按钮与图片相同大小

		jbu.setHideActionText(true);
		jbu.setToolTipText("图片按钮"); // 设置按钮提示为文字
		jbu.setBorderPainted(false); // 设置按钮边界不显示
		jbu.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				JOptionPane.showMessageDialog(null, "弹出对话框");
			}
			
		});
		URL url = JFrameBackground.class.getResource("1psu.jpg");
		ImageIcon icon = new ImageIcon(url);
		Image img = icon.getImage();

		c.add(GImage);
		c.add(jbu);
		
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		setVisible(true);
		pack();
		
		//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	}

}
